package com.sduept.nwld.dataserver.controller.riskalarm;

import com.sduept.bigdata.document.entity.core.RecordAttachment;
import com.sduept.bigdata.document.services.RecordAttachmentManager;
import com.sduept.bigdata.fault.dto.BreakerActionInfoDTO;
import com.sduept.bigdata.fault.manager.BreakerActionAnalysisManager;
import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.message.entity.AlarmMessageCheck;
import com.sduept.message.manager.AlarmMessageCheckManager;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Named
@ViewScoped
public class BreakerActException extends AbstractController {

	@Autowired
	private BreakerActionAnalysisManager bm;
	@Autowired
	private AlarmMessageCheckManager amc;
	@Autowired
	private RecordAttachmentManager ram;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private BreakerActionInfoDTO breakerAct = null;
	private String msgType = null;
	private AlarmMessageCheck check = null;
	private List<RecordAttachment> attachments = new ArrayList<>();

	@PostConstruct
	private void init() {
		String recordId = getParameter("recordId");
		String msgId = getParameter("msgId");
		msgType = getParameter("msgType");
		if (StringUtils.isNotEmpty(recordId)) {
			breakerAct = bm.getBreakerActionInfoById(recordId);
		}
		check = amc.getAlarmMessageCheckByMsgId(msgId);
		if (null == check) {
			check = new AlarmMessageCheck();
		}
		attachments = ram.getAttachmentsByOId(check.getId());
	}

	/**
	 * 格式化小数--保留两位
	 * @param value
	 * @return
	 */
	public double formatNumber(double value) {
		BigDecimal b = new BigDecimal(value);
		value = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
		return value;
	}

	public BreakerActionInfoDTO getBreakerAct() {
		return breakerAct;
	}

	public void setBreakerAct(BreakerActionInfoDTO breakerAct) {
		this.breakerAct = breakerAct;
	}

	public String getMsgType() {
		return msgType;
	}

	public void setMsgType(String msgType) {
		this.msgType = msgType;
	}

	public AlarmMessageCheck getCheck() {
		return check;
	}

	public void setCheck(AlarmMessageCheck check) {
		this.check = check;
	}

	public List<RecordAttachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(List<RecordAttachment> attachments) {
		this.attachments = attachments;
	}

}
